import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';

import { ErrorBoundary } from 'react-error-boundary';
import { Provider } from 'react-redux'; // 导入Provider组件，用于将Redux store传递给React组件树

import ErrorPage from '@/components/ErrorBoundary';
import setupDayjs from '@/plugins/dayjs';
import setupInit from '@/plugins/init.ts';
import setupNProgress from '@/plugins/nprogress';
import store from '@/store'; // 导入store

import App from './App.tsx';

import './plugins/assets'; // 导入全局样式和资源

function setupApp() {
	const container = document.getElementById('root'); // 获取根DOM节点

	if (!container) return; // 如果根节点不存在，直接返回

	const root = createRoot(container); // 创建React根节点

	// 渲染应用
	root.render(
		<ErrorBoundary fallbackRender={ErrorPage}>
			<Provider store={store}>
				<StrictMode>
					<App />
				</StrictMode>
			</Provider>
		</ErrorBoundary>
	);
	setupInit();
	setupDayjs();
	setupNProgress();
	console.log('当前环境', import.meta.env);
}

setupApp();
